package net.wofly.sale.exchange.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.wofly.framework.util.ReturnBean;
import net.wofly.sale.exchange.domain.ExchangeType;
import net.wofly.sale.exchange.service.IExchangeTypeService;
import net.wofly.sale.exchange.validator.ExchangeTypeValidator;

@RestController
@RequestMapping(value = "/api/exchange")
@Api(description = "兑换类型接口")
public class ExchangeTypeController {
	
	@Autowired
	IExchangeTypeService iExchangeTypeService ;
	
	@ApiOperation(value = "不分页获取所有兑换类型", notes = "不分页获取所有兑换类型")
	@RequestMapping(value = "/getAllExchangeTypeList", method = {RequestMethod.POST})
	@ResponseBody
	public ReturnBean<List<ExchangeType>> getAllExchangeTypeList() {
		
		return iExchangeTypeService.getAllExchangeType() ;
	}
	
	@ApiOperation(value = "添加兑换类型", notes = "添加兑换类型")
	@ApiImplicitParam(name = "exchangeType", value = "兑换类型实体", required = true, dataType = "ExchangeType", paramType = "body")
	@RequestMapping(value = "/addExchangeType", method = {RequestMethod.POST})
	@ResponseBody
	public ReturnBean<ExchangeType> saveExchangeType(@RequestBody ExchangeType exchangeType) {
		
		String errorMessage = ExchangeTypeValidator.validateAddExchangeTypeInParams(exchangeType) ;
		
        if (errorMessage.length() > 0) {
            return new ReturnBean<>(91011, errorMessage);
        }
        
        return iExchangeTypeService.saveExchangeType(exchangeType) ;
	}
	
	@ApiOperation(value = "修改兑换类型", notes = "修改兑换类型")
	@ApiImplicitParam(name = "exchangeType", value = "兑换类型实体", required = true, dataType = "ExchangeType", paramType = "body")
	@RequestMapping(value = "/updateExchangeType", method = {RequestMethod.POST})
	@ResponseBody
	public ReturnBean<ExchangeType> updateExchangeType(@RequestBody ExchangeType exchangeType) {
		
		String errorMessage = ExchangeTypeValidator.validateUpdateExchangeTypeInParams(exchangeType) ;
		
        if (errorMessage.length() > 0) {
            return new ReturnBean<>(91011, errorMessage);
        }
        
        return iExchangeTypeService.saveExchangeType(exchangeType) ;
	}
	
	@ApiOperation(value = "删除兑换类型", notes = "删除兑换类型")
	@ApiImplicitParam(name = "exchangeTypeID", value = "兑换类型ID", required = true, dataType = "String", paramType = "form")
	@RequestMapping(value = "/delExchangeType", method = {RequestMethod.POST})
	@ResponseBody
	public ReturnBean<String> delExchangeType(String exchangeTypeID) {
		
		String errorMessage = ExchangeTypeValidator.validateExchangeTypeID(exchangeTypeID);
		
        if (errorMessage.length() > 0) {
            return new ReturnBean<>(91012, errorMessage);
        }
		
		return iExchangeTypeService.delExchangeType(exchangeTypeID) ;
	}
	
	@ApiOperation(value = "分页获取所有兑换类型", notes = "分页获取所有兑换类型")
	@ApiImplicitParams({@ApiImplicitParam(name = "exchangeTypeName", value = "兑换类型名称", required = false, dataType = "String", paramType = "form"),
						@ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "form"),
						@ApiImplicitParam(name = "pageSize", value = "页大小", required = true, dataType = "int", paramType = "form")
					})
	@RequestMapping(value = "/getAllExchangeType", method = {RequestMethod.POST})
	@ResponseBody
	public ReturnBean<Page<ExchangeType>> getAllExchangeType(String exchangeTypeName ,
															@RequestParam(defaultValue = "1", name = "pageNum")Integer pageNum, 
															@RequestParam(defaultValue = "20", name = "pageSize") Integer pageSize) {
		
		return iExchangeTypeService.getAllExchangeType(exchangeTypeName ,pageNum ,pageSize) ;
	}

}
